<template>
    <div class="home">
        <my-head></my-head>
        <div class="container" id="content">
            <div class="left" id="left"></div>
            <div class="right" id="right"></div>
        </div>
    </div>
</template>

<script>
import MyHead from '@/components/common/Head'
import $ from 'jquery';
import 'jquery-ui/ui/widgets/resizable';
import { mapState } from 'vuex'
export default {
    name: 'Home',
    components: {
        MyHead
    },
    data() {
        return {

        }
    },
    computed: {
        ...mapState('common', ['curType'])
    },
    mounted() {
        let $width = document.body.clientWidth;
        $('#left').resizable({
            //'e'是east，允许拖动右侧边框的意思
            handles:'e',
            maxWidth: $width * 0.7,
            minWidth: $width * 0.3,
            // aspectRatio: true,
            //resize方法在#left大小改变后被执行
            resize:function(event, ui){
                $('#right').width($('#content').width() - ui.size.width);
            }
        });
        // 窗口改变，等比缩放
        $(window).resize(() => {
            $width = document.body.clientWidth;
            $('#left').resizable({
                maxWidth: $width * 0.7,
                minWidth: $width * 0.3,
            });
            let scalerate=$('#content').width()/($('#left').width() + $('#right').width());
            $('#left').width($('#left').width() * scalerate);
            $('#middle').width($('#middle').width() * scalerate);
            $('#right').width($('#right').width() * scalerate);
        })
        // 阻止resize事件冒泡
        $('body').bind('resize', () => {
            return false;
        })
    },
    watch: {
        curType(val) {
            this.init(val);
        }
    },
    methods: {
        init(type) {

        }
    }
};
</script>

<style lang="scss" scoped>
.home {
    width: 100%;
    height: 100%;
}
.container {
    width: 100%;
    height: calc(100% - 60px);
    display: flex;
}
.left, .right {
    width: calc(50%);
    height: 100%;
}
.left {
    background: antiquewhite;
    border-right: 2px solid aquamarine;
    position: relative;
}
.right {
    background: chocolate;
}
</style>
